package cool.webstudy.admin.service.impl.docker;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Image;
import cool.webstudy.admin.service.docker.ImageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 莫振双
 * @date 2025/3/22 14:55
 * @description: docker镜像服务实现类
 */
@Service
public class ImageServiceImpl implements ImageService {
    @Autowired
    private DockerClient dockerClient;
    @Override
    public Boolean isExistImage(String imageName) {
        if (StringUtils.isBlank(imageName)){
            return false;
        }
        List<Image> imageList = dockerClient.listImagesCmd().withImageNameFilter(imageName).exec();
        if (imageList.isEmpty()){
            return false;
        }
        return true;
    }
}
